package com.controller;


import com.domain.Employee;
import com.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    //查找所有的员工信息
    @RequestMapping("/findAll")
    public String findAll(Model model){
        List<Employee> employees = employeeService.findAll();

        model.addAttribute("employees",employees);

        return "list";
    }

    //添加员工
    @RequestMapping("/save")
    public String save(Employee employee){
        //System.out.println(employee);
        employeeService.save(employee);
        //重定向
        return "redirect:/employee/findAll";
    }


}
